﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.Logic;
using NTTDATA.BEENChina.ResultCertification.model;
using NTTDATA.BEENChina.ResultCertification.DataStore;

namespace NTTDATA.BEENChina.ResultCertification.WcfServiceLibrary
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]  
    public class ServiceResultCertification : IServiceResultCertification
    {
        

        public IEnumerable<CategoryConfig> GetCagetoryConfigs(EnumCategoryType categoryType)
        {
            return (new CategoryConfigAccess()).GetCagetoryConfigs(categoryType);
        }

        public int RemoveCategoryVerfities(string categoryId)
        {
            CategoryConfigAccess access = new CategoryConfigAccess();
            return access.RemoveCategoryVerfities(categoryId);
        }

        public List<VerfityItem> GetVerfityItems(EnumCategoryType categoryType)
        {
            return (new VerfityAccess()).GetVerfityItems(categoryType);
        }

        public int AddCategoryVerfities(string categoryId, IEnumerable<VerfityItem> verfityItems)
        {
            CategoryConfigAccess access = new CategoryConfigAccess();
            return access.AddCategoryVerfities(categoryId, verfityItems);
        }

        public CheckSetting GetCheckSetting()
        {
            CheckSetting setting = (new CheckSettingAccess()).GetCheckSetting();
            return setting;
        }

        public void SaveSettings(CheckSetting setting)
        {
            new CheckSettingAccess().SaveSettings(setting);
        }

        public void SaveVerifyCategorys(List<VerfityItem> verfityItems)
        {
            new CheckSettingAccess().SaveSelectVerfityItem(verfityItems);

        }

        public List<CheckSetting> GetCheckSettings()
        {
            return new CheckSettingAccess().GetCheckSettings();

        }

        public void AddCheckSetting(CheckSetting checkSetting)
        {
            new CheckSettingAccess().AddCheckSetting(checkSetting);

        }

        public void DelCheckSetting(string id)
        {
            new CheckSettingAccess().DelCheckSetting(id);
        }


        public VerfityItem GetVerfityItem(string verfityItemId)
        {
            VerfityItem verfityItem = (new VerfityAccess()).GetVerfityItem(verfityItemId);
            return verfityItem;
        }
 

        public int AddVerfityItem(VerfityItem verfityItem)
        {
            int effactRow = (new VerfityAccess()).AddVerfityItem(verfityItem);
            return effactRow;
        }

        public int UpdateVerfityItem(VerfityItem verfityItem)
        {
            int effactRow = (new VerfityAccess()).UpdateVerfityItem(verfityItem);
            return effactRow;
        }

        public bool VerfityItemId(string verfityItemId)
        {
            bool verfityResult = !(new VerfityAccess()).VerfityItemId(verfityItemId);
            return verfityResult;
        }
        
        public void Start()
        {
            if (WorkingState.GetInstance().CheckMonitor == null)
            {
                WorkingState.GetInstance().CheckMonitor = new CheckMonitor();
                WorkingState.GetInstance().CheckMonitor.Start();
            }
            else
            {
                WorkingState.GetInstance().Stop = false;
            }
            /*Logic.CheckMonitor checkMonitor = new CheckMonitor(); 
            checkMonitor.Start();            */
        }

        public void Stop()
        {
            WorkingState.GetInstance().Stop = true;
        }

        public void CompleteOpIdAndImage()
        {
            VerfityJob verfityJob = new VerfityJob();
            verfityJob.CompleteOpIdAndImage();;
        }

        public string DataBaseConnString()
        {
            return DataStore.DataTarget.ConnectionString;
        }
    }
}
